package com.evil.enterprise.controller;

import com.evil.account.api.RemoteDepartmentService;
import com.evil.common.account.dto.department.*;
import com.evil.common.core.entity.R;
import com.evil.common.log.annotation.RequestLogAnnotation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 部门接口
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/department")
public class DepartmentController {

    private final RemoteDepartmentService remoteDepartmentService;

    /**
     * 获取部门基础信息树
     *
     * @param departmentTreeReqDTO departmentTreeReqDTO
     * @return R
     */
    @PostMapping("/base-tree")
    public R<List<DepartmentBaseTreeRespDTO>> baseTree(@Validated @RequestBody DepartmentTreeReqDTO departmentTreeReqDTO) {
        departmentTreeReqDTO.setEnterpriseId(null);
        return R.success(remoteDepartmentService.baseTree(departmentTreeReqDTO));
    }

    /**
     * 获取部门树
     *
     * @param departmentTreeReqDTO departmentTreeReqDTO
     * @return R
     */
    @PostMapping("/tree")
    public R<List<DepartmentTreeRespDTO>> tree(@Validated @RequestBody DepartmentTreeReqDTO departmentTreeReqDTO) {
        departmentTreeReqDTO.setEnterpriseId(null);
        return R.success(remoteDepartmentService.tree(departmentTreeReqDTO));
    }

    /**
     * 企业部门基础列表
     *
     * @param departmentBasesReqDTO departmentBasesReqDTO
     * @return R
     */
    @PostMapping("/bases")
    public R<List<DepartmentBaseRespDTO>> bases(@Validated @RequestBody DepartmentBasesReqDTO departmentBasesReqDTO) {
        departmentBasesReqDTO.setEnterpriseId(null);
        return R.success(remoteDepartmentService.bases(departmentBasesReqDTO));
    }

    /**
     * 新增部门
     *
     * @param addDepartmentReqDTO addDepartmentReqDTO
     * @return R
     */
    @PostMapping("/add")
    @RequestLogAnnotation(isSaveRequestData = false, isSaveResponseData = false)
    public R<?> add(@Validated @RequestBody AddDepartmentReqDTO addDepartmentReqDTO) {
        addDepartmentReqDTO.setEnterpriseId(null);
        remoteDepartmentService.add(addDepartmentReqDTO);
        return R.success();
    }

    /**
     * 修改部门
     *
     * @param modifyDepartmentReqDTO modifyDepartmentReqDTO
     * @return R
     */
    @PostMapping("/modify")
    @RequestLogAnnotation(isSaveRequestData = false, isSaveResponseData = false)
    public R<?> modify(@Validated @RequestBody ModifyDepartmentReqDTO modifyDepartmentReqDTO) {
        modifyDepartmentReqDTO.setEnterpriseId(null);
        remoteDepartmentService.modify(modifyDepartmentReqDTO);
        return R.success();
    }

    /**
     * 删除部门
     *
     * @param deleteDepartmentReqDTO deleteDepartmentReqDTO
     * @return R
     */
    @PostMapping("/delete")
    @RequestLogAnnotation(isSaveRequestData = false, isSaveResponseData = false)
    public R<?> delete(@Validated @RequestBody DeleteDepartmentReqDTO deleteDepartmentReqDTO) {
        remoteDepartmentService.delete(deleteDepartmentReqDTO);
        return R.success();
    }
}
